package pATT.core.visual;

import java.awt.Dimension;
import java.awt.HeadlessException;
import java.awt.Toolkit;
import java.io.File;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import pATT.DataSetsGenerator.dataSetsGenerator.core.implement.RelationManager;
import pATT.DataSetsGenerator.dataSetsGenerator.core.visual.DataGenerator;
import pATT.about.About;
import pATT.logger.Logger;
import pATT.logger.Message;




public class TesisUI extends JFrame {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private JButton jDataSetsButton = null;
	private JButton jAboutButton = null;
	private JButton jUserProfilingButton = null;
	private JPanel jPanel = null;
	private JPanel jPanel1 = null;
	private JLabel jLabel = null;
	private JPanel jPanel2 = null;
	private JLabel jPresentatLabel1 = null;
	private JLabel jPresentatLabel2 = null;
	private JLabel jPresentatLabel3 = null;
	public TesisUI() throws HeadlessException {
		super();
		initialize();
	}
	/**
	 * This method initializes jDataSetsButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJDataSetsButton() {
		if (jDataSetsButton == null) {
			jDataSetsButton = new JButton();
			jDataSetsButton.setText("Datasets Generator");
			jDataSetsButton.setBackground(java.awt.SystemColor.control);
			jDataSetsButton.setBounds(new java.awt.Rectangle(34,165,146,26));
			jDataSetsButton.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
			jDataSetsButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					RelationManager.createInstance();
					DataGenerator.createInstance().show();			
				}
			});
		}
		return jDataSetsButton;
	}
	
	/**
	 * This method initializes jAboutButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJAboutButton() {
		if (jAboutButton == null) {
			jAboutButton = new JButton();
			jAboutButton.setText("About");
			jAboutButton.setBackground(java.awt.SystemColor.control);
			jAboutButton.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
			jAboutButton.setBounds(new java.awt.Rectangle(34,261,146,26));
			jAboutButton.setPreferredSize(new java.awt.Dimension(146,26));
			jAboutButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					(new About()).show();		
				}
			});
		}
		return jAboutButton;
	}
	
	/**
	 * This method initializes jUserProfilingButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJUserProfilingButton() {
		if (jUserProfilingButton == null) {
			jUserProfilingButton = new JButton();
			jUserProfilingButton.setText("PATT");
			jUserProfilingButton.setBackground(java.awt.SystemColor.control);
			jUserProfilingButton.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
			jUserProfilingButton.setBounds(new java.awt.Rectangle(34,213,146,26));
			jUserProfilingButton.setPreferredSize(new java.awt.Dimension(146,26));
			jUserProfilingButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					
					//Se chequea que se haya agregado la carpeta PATT Files en la ubicacion correcta
					if(!new File(Message.PATH_PATH_FILES).isDirectory()){
						 JOptionPane.showMessageDialog(TesisUI.this,
								 '"'+"PATT files"+'"'+" folder is not in the directory C:/",
								  "Inicialization Error",
								  JOptionPane.ERROR_MESSAGE);
//						 dispose();
					}else{

					
					//UserProfilingUI.createInstance();
					UserProfilingUI.eINSTANCE.show();
					Logger.logInitial();
					}
				}
			});
		}
		return jUserProfilingButton;
	}
	
	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel() {
		if (jPanel == null) {
			jPanel = new JPanel();
			jPanel.setLayout(null);
			jPanel.setBounds(new java.awt.Rectangle(5,5,216,303));
			jPanel.setBackground(new java.awt.Color(73,86,119));
			jPanel.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.black,3));
			jPanel.add(getJDataSetsButton(), null);
			jPanel.add(getJUserProfilingButton(), null);
			jPanel.add(getJAboutButton(), null);
			jPanel.add(getJPanel2(), null);
		}
		return jPanel;
	}
	
	/**
	 * This method initializes jPanel1	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel1() {
		if (jPanel1 == null) {
			jLabel = new JLabel();
			jLabel.setText("");
			//jLabel.setIcon(new ImageIcon(getClass().getResource("/pATT/icon/Puesta de sol1.gif")));
			jLabel.setIcon(new ImageIcon(getClass().getResource("/pATT/icon/pattLupa1.gif")));
			jLabel.setBounds(new java.awt.Rectangle(2,3,356,298));
			jPanel1 = new JPanel();
			jPanel1.setLayout(null);
			jPanel1.setBounds(new java.awt.Rectangle(224,5,361,303));
			jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.black,3));
			jPanel1.setBackground(java.awt.SystemColor.inactiveCaptionBorder);
			jPanel1.add(jLabel, null);
		}
		return jPanel1;
	}
	
	/**
	 * This method initializes jPanel2	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel2() {
		if (jPanel2 == null) {
			jPresentatLabel3 = new JLabel();
			jPresentatLabel3.setText("Profiling Algorithm Testing Tool");
			jPresentatLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
			jPresentatLabel3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
			jPresentatLabel3.setForeground(java.awt.Color.red);
			jPresentatLabel3.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.BOLD, 11));
			jPresentatLabel3.setPreferredSize(new java.awt.Dimension(190,20));
			jPresentatLabel2 = new JLabel();
			jPresentatLabel2.setText("Tandil - 2007");
			jPresentatLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
			jPresentatLabel2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
			jPresentatLabel2.setForeground(java.awt.Color.red);
			jPresentatLabel2.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.BOLD, 11));
			jPresentatLabel2.setPreferredSize(new java.awt.Dimension(190,20));
			jPresentatLabel1 = new JLabel();
			jPresentatLabel1.setText("Universidad Nacional del Centro");
			jPresentatLabel1.setForeground(java.awt.Color.red);
			jPresentatLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
			jPresentatLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
			jPresentatLabel1.setPreferredSize(new java.awt.Dimension(190,20));
			jPresentatLabel1.setFont(new java.awt.Font("Microsoft Sans Serif", java.awt.Font.BOLD, 11));
			jPanel2 = new JPanel();
			jPanel2.setBounds(new java.awt.Rectangle(7,19,203,89));
			jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.black,2));
			jPanel2.setBackground(new java.awt.Color(40,22,111));
			jPanel2.add(jPresentatLabel3, null);
			jPanel2.add(jPresentatLabel1, null);
			jPanel2.add(jPresentatLabel2, null);
		}
		return jPanel2;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new TesisUI().show();
	}
	
	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
	    GenericObjectEditor.registerEditors(); 

		LookAndFeel.setLookAndFeel();
		
		this.setSize(600, 346);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setResizable(false);
		Dimension pantalla = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension freim = this.getSize();
		if (pantalla.width < freim.width){
			freim.width = pantalla.width;
		}
		if (pantalla.height < freim.height) {
			freim.height = pantalla.height;
		}
		this.setLocation((pantalla.width-freim.width)/2,(pantalla.height-freim.height)/2);

		this.setContentPane(getJContentPane());
		this.setTitle("Profiling Algorithm Testing Tool");
		
		
	}
	
	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.setBackground(java.awt.SystemColor.control);
			jContentPane.add(getJPanel(), null);
			jContentPane.add(getJPanel1(), null);
		}
		return jContentPane;
	}
	
}  //  @jve:decl-index=0:visual-constraint="10,10"
